/**
 * @param {string} str
 * @returns {string}
 */
function removeNewlineAndTrailingSpace(str) {
  return str.replaceAll(/(?<=>)\s+(?=<)/g, "").trim();
  // .replace(/(\r|\n)\s*/g, "");
}

// test-case
// const testStr = "abc\r\ndef \r ghi\n jkl";
// const result = removeNewlineAndTrailingSpace(testStr);
// console.log(result);
/**
 * #__NO_SIDE_EFFECTS__
 * #__INLINE__
 * @type {(text: TemplateStringsArray, ...args: {toString(): string}[])=>string}
 */
export const html = (text, ...args) => {
  /**
   * @type {string[]}
   */
  const result = [];
  // for(text, args)
  for (let i = 0; i < args.length; i++) {
    result.push(text[i] + args[i].toString());
  }
  const last = text[text.length - 1];
  if (last) {
    result.push(last);
  }
  return removeNewlineAndTrailingSpace(result.join("").trim());
};
/**
 * #__NO_SIDE_EFFECTS__
 * @desc use fewer
 * @type {(text: TemplateStringsArray, ...args: { toString(): string }[])=>string}
 */
export const css = (text, ...args) => {
  const result = [];
  for (let i = 0; i < args.length; i++) {
    result.push(text[i] + args[i].toString());
  }
  const last = text.at(-1);
  if (last) {
    result.push(last);
  }
  return result.join("").trim();
};
